package com.boco.blch.analysiser.compliance.HW.manager;

import com.boco.blch.analysiser.compliance.ComplianceResolved;

/**
 * Kafka接口认证安全基线要求项
 * @author admin
 *
 */
public class BOCO_Kafka_IdentityAuth_InterfaceAuth implements ComplianceResolved {

	private final static String HADOOP_SECURITY_AUTHENTICATION = "HADOOP_SECURITY_AUTHENTICATION=kerberos";
	private final static String ALLOW_EVERYONE_IF_NO_ACL_FOUND = "ALLOW.EVERYONE.IF.NO.ACL.FOUND=false";
	
	@Override
	public int realEchoResolved(String echoResult) {
		/*查看/opt/huawei/Bigdata/etc/2_26_Broker/目录下的ENV_VARS里面的变量：HADOOP_SECURITY_AUTHENTICATION的值应该为：kerberos*/
		int result = FAILED;
		if(echoResult != null && echoResult.length() > 0){
			//------------0.9以下版本-------------
			if(echoResult.indexOf("Broker-start") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Broker-start")+"Broker-start".length(), echoResult.indexOf("Broker-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("Producer-start") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Producer-start")+"Producer-start".length(), echoResult.indexOf("Producer-end")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("Consumer-start") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Consumer-start")+"Consumer-start".length(), echoResult.indexOf("Consumer-end")).trim();
				result = getResult(strResult);
			}
			//------------0.9以上版本-------------
			if(result == FAILED && echoResult.indexOf("Broker-start2") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Broker-start2")+"Broker-start2".length(), echoResult.indexOf("Broker-end2")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("Producer-start2") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Producer-start2")+"Producer-start2".length(), echoResult.indexOf("Producer-end2")).trim();
				result = getResult(strResult);
			}
			if(result == FAILED && echoResult.indexOf("Consumer-start2") != -1){
				String strResult = echoResult.substring(echoResult.indexOf("Consumer-start2")+"Consumer-start2".length(), echoResult.indexOf("Consumer-end2")).trim();
				result = getResult(strResult);
			}
		}
		return result;
	}
	

	private int getResult(String echoResult){
		int result = FAILED;
		if(echoResult != null){
			echoResult = echoResult.replace(" ", "");
		}
		if(echoResult != null && (echoResult.contains(HADOOP_SECURITY_AUTHENTICATION) 
				|| echoResult.contains(ALLOW_EVERYONE_IF_NO_ACL_FOUND))){
			result = SUCCESS;
		}
		return result;
	}
	
	
	

	

}
